//
//  ROLogonViewController.swift
//  燃脂健身
//
//  Created by cuibaoliang on 2017/9/26.
//  Copyright © 2017年 cuibaoliang. All rights reserved.
//

import UIKit

class ROLogonViewController: UIViewController {
    @IBOutlet weak var Tel: UITextField!
    @IBOutlet weak var Pwd: UITextField!
    @IBAction func logon(_ sender: UIButton) {
        if Tel.text == ""{
            MBProgressHUD.showDelayHUDToView(self.view, message: "手机号码没有输入")
        }else{
            if Pwd.text == ""{
                //print("密码咩有输入")
                MBProgressHUD.showDelayHUDToView(self.view, message: "密码没有输入")
            } else {
                //验证用户名和密码
                let parameters: NSDictionary = ["tel": Tel.text!,"password": Pwd.text!] as NSDictionary
                RONetworkMngTool.shareNetworkMngTool().RONetwork_Logon(parameters, view: self.view, block: { (flag) -> Void in
                    if flag == "1" {
                        //本地存储用户的其他信息
                        //                        ROLogonReturnModel.getUserInformation()
                        //
                        //                        let _ = (ACSimpleKeychain.defaultKeychain() as AnyObject).storeUsername(self.userName.text, password: self.passWord.text, identifier: "user1", forService: "userpassword")
                        //登陆到主界面
                        //测试暂时先把这句去掉
                        //UIApplication.shared.keyWindow!.rootViewController = ROMainTabBarViewController()
                    } else {
                        //清空用户名和密码
                        //                        let _ = (ACSimpleKeychain.defaultKeychain() as AnyObject).deleteAllCredentials(forService: "userpassword")
                        //                        let _ =  (ACSimpleKeychain.defaultKeychain() as AnyObject).storeUsername("", password: "", identifier: "user1", forService: "userpassword")
                    }
                })
            }
        }
    }
}
